package com.qlslylq.ad.sdk.core.ad;

import com.qlslylq.ad.sdk.application.AdMergeSDKApp;
import com.qlslylq.ad.sdk.method.BaseMethod;
import com.qlslylq.ad.sdk.model.rsp.AdPlaceWebConfigureVO;
import com.qlslylq.ad.sdk.util.GsonUtils;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * created by qlslylq <br/>
 * on 2022/2/11 <br/>
 * 广告基类 <br/>
 */
public class BaseAd {

    //广告
    private Object ad;

    //广告配置
    private AdPlaceWebConfigureVO config;

    //加载完成时间
    private String time;

    public BaseAd(Object ad, AdPlaceWebConfigureVO config) {
        if (AdMergeSDKApp.isDebug()) {
            time = BaseMethod.getCurrentTime();
        }
        this.ad = ad;
        this.config = config;
    }

    public Object getAd() {
        return ad;
    }

    public void setAd(Object ad) {
        this.ad = ad;
    }

    public AdPlaceWebConfigureVO getConfig() {
        return config;
    }

    public void setConfig(AdPlaceWebConfigureVO config) {
        this.config = config;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    /**
     * 获取排序要素-权重<br/>
     */
    public int getWeight() {
        return getConfig().getWeight();
    }

    public String toString() {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("ad", "ad-" + getTime());
        map.put("config", getConfig());
        map.put("time", getTime());
        return GsonUtils.gsonString(map);
    }
}
